<?php
/**
 * Created By base
 * Author: Virus
 * Date: 2020/4/4
 * Time: 17:38
 */

namespace app\common\model\mysql;


use app\admin\lib\Curd;
use think\model\concern\SoftDelete;

class Article extends BaseModel
{
    use Curd;

    use SoftDelete;

    protected $deleteTime = 'delete_time';

    protected $append = [
        'status_text',
    ];

    /**
     * 状态值用status_text输出
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getStatusTextAttr($value, $data)
    {
        $status = [0 => '审核不通过', 1 => '审核通过', 2 => '待审核'];

        return $status[$data['status']];
    }

    /**
     * 是否置顶获取器
     * @param $value
     * @return string
     */
    public function getIsTopAttr($value)
    {
        return $value ? '是' : '否';
    }

    /**
     * 关联分类表
     * @return \think\model\relation\BelongsTo
     */
    public function categories()
    {
        return $this->belongsTo(Category::class, 'category_id', 'id');
    }
}